/*
* 文件：EscExit.cs
* 作者：王阳
* 时间：2019-5-20
* 描述：按Esc键退出程序
*/

//#define ENABLED
#if ENABLED

using UnityEngine;

namespace UnityX
{
    internal class EscExit : MonoBehaviour
    {
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
        private static void AfterSceneLoad()
        {
            GameObject go = new GameObject("_EscExit_");
            go.hideFlags = HideFlags.HideInHierarchy;
            DontDestroyOnLoad(go);
            go.AddComponent<EscExit>();
        }
        private void Update()
        {
            if (UnityEngine.Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
#endif
            }
        }
    }
}
#endif